# 请在此输入您的代码
n = int(input())
gaps = list(map(int, input().split()))

max_element = n
cnt = 0
while gaps:
    if gaps[-1] != max_element:
        cnt += 1
    else:
        max_element -= 1
    gaps.pop()
print(cnt)
